<template>
	<view class="user-layout page-background">

		<view class="" :style="{height: getNavBarHeight() + 'px'}">

		</view>

		<view class="user-info">
			<view class="avatar">
				<image src="/static/images/xxmLogo.png" mode="aspectFill"></image>
			</view>

			<view class="ip">{{userInfo.IP}}</view>
			<view class="ipAddress">归属地：{{userInfo?.address?.province}}</view>
		</view>




		<view class="section">
			<view class="list">
				<navigator url="/pages/class-list/class-list?name=我的下载&type=download">
					<view class="row">
						<view class="row-left">
							<uni-icons type="download-filled" size="20"></uni-icons>
							<text class="text">我的下载</text>
						</view>
						<view class="row-right">
							<text class="downloads">{{userInfo.downloadSize}}</text>
							<uni-icons type="right" size="15" color="28b389"></uni-icons>
						</view>
					</view>
				</navigator>

				<navigator url="/pages/class-list/class-list?name=我的评分&type=score">
					<view class="row">
						<view class="row-left">
							<uni-icons type="star-filled" size="20"></uni-icons>
							<text class="text">我的评分</text>
						</view>
						<view class="row-right">
							<text class="downloads">{{userInfo.scoreSize}}</text>
							<uni-icons type="right" size="15" color="28b389"></uni-icons>
						</view>
					</view>
				</navigator>


				<view class="row">
					<view class="row-left">
						<uni-icons type="chatboxes-filled" size="20"></uni-icons>
						<text class="text">联系客服</text>
					</view>
					<view class="row-right">
						<text class="downloads"></text>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>

					<!-- 小程序端 -->
					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->


					<!-- 非小程序端 -->
					<!-- #ifndef MP -->
					<button @click="contactByPhone">拨打电话</button>
					<!-- #endif -->

				</view>


			</view>
		</view>


		<view class="section">
			<view class="list">
				<navigator url="/pages/notice/detail?id=653507c6466d417a3718e94b ">
					<view class="row">
						<view class="row-left">
							<uni-icons type="notification-filled" size="20"></uni-icons>
							<text class="text">订阅更新</text>
						</view>
						<view class="row-right">
							<text class="downloads">0</text>
							<uni-icons type="right" size="15" color="#aaa"></uni-icons>
						</view>
					</view>
				</navigator>

				<navigator url="/pages/notice/detail?id=6536358ce0ec19c8d67fbe82">
					<view class="row">
						<view class="row-left">
							<uni-icons type="help-filled" size="20"></uni-icons>
							<text class="text">常见问题</text>
						</view>
						<view class="row-right">
							<text class="downloads">0</text>
							<uni-icons type="right" size="15" color="#aaa"></uni-icons>
						</view>
					</view>
				</navigator>


			</view>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref } from 'vue';
	import { getNavBarHeight } from '@/utils/system'
	import { apiGetUserInfo } from '@/api/apis'
	import { onLoad } from '@dcloudio/uni-app'


	const userInfo = ref({})

	// 联系客服
	const contactByPhone = () => {
		uni.makePhoneCall({
			phoneNumber: '17339345395'
		})
	}

	onLoad(() => {
		getUserInfo()
	})

	const getUserInfo = async () => {
		const result = await apiGetUserInfo()
		userInfo.value = result.data
	}
</script>

<style lang="scss" scoped>
	.user-layout {
		.user-info {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding: 30rpx 0 0 0;

			.avatar {
				margin-bottom: 20rpx;
				width: 160rpx;
				height: 160rpx;
				// border: 1rpx solid red;
				// background-color: red;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}

			}

			.ip {
				padding: 20rpx 0 5rpx;
				font-size: 44rpx;
				color: #333;
			}

			.ipAddress {
				font-size: 28rpx;
				color: #aaa;
			}
		}

		.section {
			// padding: 30rpx;
			margin: 50rpx auto;
			width: 690rpx;
			border: 1px solid #eee;
			border-radius: 10rpx;
			// box-shadow: 水平偏移 垂直偏移 模糊半径 颜色
			box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);

			.list {
				.row {
					// border: 1rpx solid red;
					position: relative;
					display: flex;
					justify-content: space-between;
					// align-items: center;
					border-bottom: 1rpx solid #eee;
					padding: 0 30rpx;
					height: 100rpx;
					background-color: white;

					&:last-child {
						border-bottom: 0;
					}

					.row-left {
						display: flex;
						justify-content: center;
						align-items: center;

						::v-deep {
							.uni-icons {
								color: $brand-theme-color !important;
							}
						}

						.text {
							padding-left: 10rpx;
							color: #666;
						}
					}

					.row-right {
						display: flex;
						justify-content: center;
						align-items: center;

						.downloads {
							font-size: 28rpx;
							color: #aaa;
						}
					}

					button {
						position: absolute;
						top: 0;
						left: 0;
						width: 100%;
						height: 100%;
						opacity: 0;
					}
				}
			}
		}
	}
</style>